<?php
/**
 * Created by PhpStorm.
 * User: 23221
 * Date: 2019/2/25
 * Time: 9:02
 */

namespace App\Services\Resume;


use App\Model\Resume;
use App\Model\ReUser;
use App\Services\Campaign\Platform\CommentService;

class ResumeServices extends CommentService{
    // 简历列表
    public function resumeList(){
        return Resume::all()->where('resume_enabled',1);
    }
    // 简历详情
    public function resumeDetails($id){
        // 关联模型查询用户的所有简历
        return ReUser::with('hasManyResume')->find($id);
    }
    // 点击创建简历按钮后生成用户基本信息简历
    public function createBaseResume($data){
         return Resume::insertGetId([
            'resume_name' => $data['resume_name'],
            'resume_user_id' => '1',
            'resume_enabled'=>$data['resume_enabled'] // 简历是否启用状态
        ]);
    }
    // // 新建简历
    // public function createResumeObjective($data){
    //     $resume_id = Resume::insertGetId([
    //         'resume_work'=>$data['resume_work'],
    //         'resume_expected_position'=>$data['resume_expected_position'],
    //         'resume_min'=>$data['resume_min'],
    //         'resume_max'=>$data['resume_max'],
    //         'resume_work_status'=>$data['resume_work_status'],
    //         'resume_working_site'=>$data['resume_working_site'],
    //         // 'resume_enabled'=>$data['resume_enabled'] // 简历是否启用状态
    //     ]);
    //     return ['state'=>true,'resume_id'=>$resume_id];
    // }
    // 编辑简历 - 保存求职意向信息
    public function editResumeObjective($data){
//        $detailModel = $this->resumeDetails($data['id']);
//        $detailModel->resume_nature = $data['resume_nature']; // 工作性质
//        $detailModel->resume_expected_position = $data['resume_expected_position']; // 期望职位
//        $detailModel->resume_min = $data['resume_min']; // 最低薪资
//        $detailModel->resume_max = $data['resume_max']; // 最高工资
//        $detailModel->resume_working_hours = $data['resume_working_hours']; // 工作时间
//        $detailModel->resume_working_site = $data['resume_working_site']; // 工作地点
        return Resume::where('resume_id',$data['resume_id'])->update([
            'resume_work'=>$data['resume_work'],
            'resume_expected_position'=>$data['resume_expected_position'],
            'resume_min'=>$data['resume_min'],
            'resume_max'=>$data['resume_max'],
            'resume_work_status'=>$data['resume_work_status'],
            'resume_working_site'=>$data['resume_working_site'],
            'resume_enabled'=>$data['resume_enabled']
        ]);
    }
    // 新建简历 - 保存实习/工作信息
    public function createResumeInternships($data){
        $resume_id = $resume_id = Resume::insertGetId([
            'resume_enabled' => 0, 
            'resume_internship_experience'=>json_encode($data),
        ]);
        return ['state'=>true,'resume_id'=>$resume_id];
    }
    // 编辑简历 - 保存实习/工作信息
    public function editResumeInternships($data){
        return Resume::where('resume_id',$data['resume_id'])->update([
            'resume_internship_experience'=>json_encode($data),
        ]);
    } 
    // 编辑简历 - 简历基本信息修改
    public function editResumeBasicInfo($data){
        return Resume::where('resume_id',$data['resume_id'])->update([
            'resume_real_name'=>$data['resume_real_name'],
            'resume_user_sex'=>$data['resume_user_sex'],
            'resume_born'=>$data['resume_born'],
            'resume_lives_city'=>$data['resume_lives_city'],
            'resume_native_place'=>$data['resume_native_place'],
            'resume_user_phone'=>$data['resume_user_phone'],
            'resume_user_email'=>$data['resume_user_email'],
            'resume_political_face'=>$data['resume_political_face'],
            'resume_enabled'=>$data['resume_enabled'],
        ]);
    }   
    // 新建简历 - 简历基本信息添加
    public function createResumeBasicInfo($data){
        return Resume::insertGetId([
            'resume_real_name'=>$data['resume_real_name'],
            'resume_user_sex'=>$data['resume_user_sex'],
            'resume_born'=>$data['resume_born'],
            'resume_lives_city'=>$data['resume_lives_city'],
            'resume_native_place'=>$data['resume_native_place'],
            'resume_user_phone'=>$data['resume_user_phone'],
            'resume_user_email'=>$data['resume_user_email'],
            'resume_political_face'=>$data['resume_political_face'],
            'resume_enabled'=>$data['resume_enabled'],
        ]);
    }  

    // 编辑简历 - 教育背景
    public function editResumeEducation($data){
        return Resume::where('resume_id',$data['resume_id'])->update([
            'resume_school_name'=>$data['resume_school_name'],
            'resume_education'=>$data['resume_education'],
            'resume_major_name'=>$data['resume_major_name'],
            'resume_admission_date'=>$data['resume_admission_date'],
            'resume_graduate_date'=>$data['resume_graduate_date'],
        ]);
    }
    // 新建简历 - 教育背景
    public function createResumeEducation($data){
        return Resume::insertGetId([
            'resume_school_name'=>$data['resume_school_name'],
            'resume_education'=>$data['resume_education'],
            'resume_major_name'=>$data['resume_major_name'],
            'resume_admission_date'=>$data['resume_admission_date'],
            'resume_graduate_date'=>$data['resume_graduate_date'],
            'resume_enabled'=>$data['resume_enabled'],
        ]);
    }

    // 编辑简历 - 提交所有剩余信息
    public function editallResumeMsg($data){
        return Resume::where('resume_id',$data['resume_id'])->update([
            'resume_competitions'=>$data['resume_competitions'],
            'resume_comment'=>$data['resume_comment'],
            'resume_practice'=>$data['resume_practice'],
            'resume_other'=>$data['resume_other'],
        ]);
    }

    // 新建简历 - 提交所有剩余信息
    public function createallResumeMsg($data){
        return Resume::insertGetId([
            'resume_competitions'=>$data['resume_competitions'],
            'resume_comment'=>$data['resume_comment'],
            'resume_practice'=>$data['resume_practice'],
            'resume_other'=>$data['resume_other'],
            'resume_enabled'=>$data['resume_enabled'],
        ]);
    }
}